package com.cxyd.modules.wcs.controller;

import com.cxyd.common.annotation.LogOperation;
import com.cxyd.common.constant.WcsConstants;
import com.cxyd.common.page.PageData;
import com.cxyd.common.utils.ProcResult;
import com.cxyd.common.utils.Result;
import com.cxyd.modules.wcs.dto.TrkDTO;
import com.cxyd.modules.wcs.service.TrkService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("wcs/trk")
public class TrkController {
    private final TrkService trkService;

    public TrkController(TrkService trkService) {
        this.trkService = trkService;
    }

    @GetMapping("page")
    @RequiresPermissions("wcs:trk:page")
    public Result<PageData<TrkDTO>> page(@RequestParam Map<String, Object> params) {
        PageData<TrkDTO> page = trkService.page(params);

        return new Result<PageData<TrkDTO>>().ok(page);
    }

    @PostMapping("/operate")
    @LogOperation("人为操作")
    @RequiresPermissions("wcs:trk:operate")
    public Result forceDone(@RequestParam Map<String, Object> params) {
        ProcResult procResult = trkService.trkHandler(params);
        if (WcsConstants.PROC_CODE_SUCCESS.equals(procResult.getCode())) {
            return new Result().ok("success");
        }
        return new Result().error(500, procResult.getMsg());
    }
}
